package view;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

import javax.swing.JFrame;
import javax.swing.JLabel;

import mappingBD.Client;
import mappingBD.Message;
import model.ChatModel;
import controller.ClientControler;

public class ChatView {
	
	private ClientControler controlleur;
	private ChatModel modele;

	private javax.swing.JFrame frame;
	private javax.swing.JButton jButtonAjouterSalleDiscussion;
    private javax.swing.JButton jButtonDesabonnerSD;
    private javax.swing.JButton jButtonModifierProfil;
    private javax.swing.JButton jButtonQuitter;
    private javax.swing.JButton jButtonQuitterSD;
    private javax.swing.JButton jButtonSoumettreMessage;
    private javax.swing.JButton jButtonAime;
    private javax.swing.JComboBox jComboBoxSallesDiscussions;
    private javax.swing.JLabel jLabelBannierePrincipale;
    private javax.swing.JLabel jLabelIconOffline;
    private javax.swing.JLabel jLabelIconOnline;
    private javax.swing.JLabel jLabelPseudoClientDansSD1;
    private javax.swing.JLabel jLabelPseudoClientDansSD2;
    private javax.swing.JLabel jLabelSallesDiscussionsDispo;
    private javax.swing.JLabel jLabelTitreSalleDiscussion;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanelBanierePrincipale;
    private javax.swing.JPanel jPanelConsulterProfil;
    private javax.swing.JPanel jPanelConsulterProfil2;
    private javax.swing.JPanel jPanelContenuSalleDiscussion;
    private javax.swing.JPanel jPanelDesabonnerSD;
    private javax.swing.JPanel jPanelOtherClientsAvatar;
    private javax.swing.JPanel jPanelQuitter;
    private javax.swing.JPanel jPanelQuitterSD;
    private javax.swing.JPanel jPanelSallesDiscussionsDispo;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPaneListeMessages;
    private javax.swing.JTextArea jTextAreaEnterMessage;
    private javax.swing.JTextPane jTextAreaTousLesMessages;
    
    public ChatView(ChatModel modele, ClientControler controlleur) {
    	this.modele = modele;
    	this.controlleur = controlleur;
        initComponents();
    }
    
	public void showView() {
		this.frame.setVisible(true);
	}
	
	public void closeView() {
		this.frame.setVisible(false);
	}
	
//    void setback() {
//        jPanelMainSalleDiscussion.setBackground(new java.awt.Color(-9491984,true));
//    }
    
    private void initComponents() {
		frame = new JFrame();
        jPanelBanierePrincipale = new javax.swing.JPanel();
        jLabelBannierePrincipale = new javax.swing.JLabel();
        jPanelOtherClientsAvatar = new javax.swing.JPanel();
        jLabelIconOnline = new javax.swing.JLabel();
        jLabelIconOffline = new javax.swing.JLabel();
        jPanelSallesDiscussionsDispo = new javax.swing.JPanel();
        jLabelSallesDiscussionsDispo = new javax.swing.JLabel();
        jComboBoxSallesDiscussions = new javax.swing.JComboBox();
        jPanelQuitter = new javax.swing.JPanel();
        jButtonQuitter = new javax.swing.JButton();
        jPanelContenuSalleDiscussion = new javax.swing.JPanel();
        jLabelTitreSalleDiscussion = new javax.swing.JLabel();
        jTextAreaTousLesMessages = new javax.swing.JTextPane();
        jScrollPaneListeMessages = new javax.swing.JScrollPane();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextAreaEnterMessage = new javax.swing.JTextArea();
        jButtonSoumettreMessage = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jLabelPseudoClientDansSD1 = new javax.swing.JLabel();
        jLabelPseudoClientDansSD2 = new javax.swing.JLabel();
        jPanelDesabonnerSD = new javax.swing.JPanel();
        jButtonDesabonnerSD = new javax.swing.JButton();
        jPanelQuitterSD = new javax.swing.JPanel();
        jButtonQuitterSD = new javax.swing.JButton();
        jPanelConsulterProfil2 = new javax.swing.JPanel();
        jButtonAjouterSalleDiscussion = new javax.swing.JButton();
        jPanelConsulterProfil = new javax.swing.JPanel();
        jButtonModifierProfil = new javax.swing.JButton();
        jButtonAime = new javax.swing.JButton();

        frame.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jPanelBanierePrincipale.setBackground(new java.awt.Color(-9491984,true));

        jLabelBannierePrincipale.setFont(new java.awt.Font("Dialog", 1, 48)); // NOI18N
        jLabelBannierePrincipale.setForeground(new java.awt.Color(-855788,true));
        jLabelBannierePrincipale.setText("Le plus meilleur chat");
        jLabelBannierePrincipale.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);

        javax.swing.GroupLayout jPanelBanierePrincipaleLayout = new javax.swing.GroupLayout(jPanelBanierePrincipale);
        jPanelBanierePrincipale.setLayout(jPanelBanierePrincipaleLayout);
        jPanelBanierePrincipaleLayout.setHorizontalGroup(
            jPanelBanierePrincipaleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelBanierePrincipaleLayout.createSequentialGroup()
                .addGap(281, 281, 281)
                .addComponent(jLabelBannierePrincipale)
                .addContainerGap(288, Short.MAX_VALUE))
        );
        jPanelBanierePrincipaleLayout.setVerticalGroup(
            jPanelBanierePrincipaleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelBanierePrincipaleLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabelBannierePrincipale)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanelOtherClientsAvatar.setBackground(new java.awt.Color(-855608,true));
        jPanelOtherClientsAvatar.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(-855788,true), 5, true));

        ArrayList<JLabel> listeJLabelClient = new ArrayList<JLabel>();
        for (Client client : modele.getListeClients()) {
        	listeJLabelClient.add(new JLabel());
//        	listeJLabelClient.get(listeJLabelClient.size()-1).setIcon(new javax.swing.ImageIcon(client.getAvatar()));
        	listeJLabelClient.get(listeJLabelClient.size()-1).setText(client.getPseudo());
        	listeJLabelClient.get(listeJLabelClient.size()-1).setToolTipText(client.getPseudo());
        	if (!client.isStatusDeConnection()) {
        		listeJLabelClient.get(listeJLabelClient.size()-1).setEnabled(false);
        	}	
        	jPanelOtherClientsAvatar.add(listeJLabelClient.get(listeJLabelClient.size()-1));
        }

        jPanelSallesDiscussionsDispo.setBackground(new java.awt.Color(-855608,true));
        jPanelSallesDiscussionsDispo.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(-855788,true), 5, true));

        jLabelSallesDiscussionsDispo.setFont(new java.awt.Font("Dialog", 0, 24)); // NOI18N
        jLabelSallesDiscussionsDispo.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabelSallesDiscussionsDispo.setText("<HTML><CENTER>Joindre une salle<BR>de discussion</HTML>");

        jComboBoxSallesDiscussions.setModel(new javax.swing.DefaultComboBoxModel(modele.getListeSalleDiscussions().toArray()));
//        jComboBoxSallesDiscussions.addActionListener(new ActionListener() {
//            @Override
//            public void actionPerformed(ActionEvent e) {
//                controlleur.selectionSalleDiscussion(jComboBoxSallesDiscussions.getSelectedIndex());
//            }
//        });

        javax.swing.GroupLayout jPanelSallesDiscussionsDispoLayout = new javax.swing.GroupLayout(jPanelSallesDiscussionsDispo);
        jPanelSallesDiscussionsDispo.setLayout(jPanelSallesDiscussionsDispoLayout);
        jPanelSallesDiscussionsDispoLayout.setHorizontalGroup(
            jPanelSallesDiscussionsDispoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelSallesDiscussionsDispoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelSallesDiscussionsDispoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelSallesDiscussionsDispoLayout.createSequentialGroup()
                        .addGap(12, 12, 12)
                        .addComponent(jComboBoxSallesDiscussions, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jLabelSallesDiscussionsDispo, javax.swing.GroupLayout.DEFAULT_SIZE, 237, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanelSallesDiscussionsDispoLayout.setVerticalGroup(
            jPanelSallesDiscussionsDispoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelSallesDiscussionsDispoLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabelSallesDiscussionsDispo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jComboBoxSallesDiscussions, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(305, Short.MAX_VALUE))
        );

        jPanelQuitter.setBackground(new java.awt.Color(-855608,true));
        jPanelQuitter.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(-855788,true), 5, true));

        jButtonQuitter.setFont(new java.awt.Font("Dialog", 0, 18));
        jButtonQuitter.setText("<HTML><CENTER>Quitter</HTML>");
        jButtonQuitter.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e){
				controlleur.quitterApp();
            }
        });

        javax.swing.GroupLayout jPanelQuitterLayout = new javax.swing.GroupLayout(jPanelQuitter);
        jPanelQuitter.setLayout(jPanelQuitterLayout);
        jPanelQuitterLayout.setHorizontalGroup(
            jPanelQuitterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelQuitterLayout.createSequentialGroup()
                .addContainerGap(42, Short.MAX_VALUE)
                .addComponent(jButtonQuitter, javax.swing.GroupLayout.PREFERRED_SIZE, 162, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(57, 57, 57))
        );
        jPanelQuitterLayout.setVerticalGroup(
            jPanelQuitterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelQuitterLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jButtonQuitter, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanelContenuSalleDiscussion.setBackground(new java.awt.Color(-855608,true));
        jPanelContenuSalleDiscussion.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(-855788,true), 5, true));

        jLabelTitreSalleDiscussion.setFont(new java.awt.Font("Dialog", 0, 36)); // NOI18N
        jLabelTitreSalleDiscussion.setText(modele.getSalle().getNomSalle());
        jLabelTitreSalleDiscussion.setToolTipText(modele.getSalle().getDescription());

//        jTextAreaTousLesMessages.setColumns(20);
//        jTextAreaTousLesMessages.setRows(5);
        jTextAreaTousLesMessages.setEditable(false);
        jTextAreaTousLesMessages.setContentType("text/html");
        StringBuilder texte = new StringBuilder();
        texte.append("<HTML>");
        for (Message mes : modele.getSalle().getListeMessages()) {
        	texte.append("(id = " + Integer.toString(mes.getIdMsg()) + ")");
        	texte.append("<FONT COLOR=\"blue\"> (");
        	texte.append(mes.getPseudoAuteur());
        	texte.append("): </FONT>");
        	texte.append(mes.getContenue());
        	texte.append("&nbsp;&nbsp;&nbsp;&nbsp(<FONT COLOR=\"green\"> +");
        	texte.append(mes.getLike());
        	texte.append("</FONT>, <FONT COLOR=\"red\"> -");
        	texte.append(mes.getDislike());
        	texte.append("</FONT> )<BR>");
        }
        texte.append("</HTML>");
        jTextAreaTousLesMessages.setText(texte.toString());
        jScrollPaneListeMessages.setViewportView(jTextAreaTousLesMessages);
        
        jTextAreaEnterMessage.setColumns(20);
        jTextAreaEnterMessage.setRows(5);
        jTextAreaEnterMessage.setText("Entrer un message...");
        jScrollPane1.setViewportView(jTextAreaEnterMessage);

        jButtonSoumettreMessage.setText("Soumettre");
        jButtonSoumettreMessage.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e){
				controlleur.soumettreMessage(jTextAreaEnterMessage.getText());
            }
        });

        jPanel1.setBackground(new java.awt.Color(-855608,true));

        ArrayList<JLabel> listeJLabelClientsDansSD = new ArrayList<JLabel>();
        for (Client client : modele.getSalle().getListAbonnes()) {
        	listeJLabelClientsDansSD.add(new JLabel());
        	listeJLabelClientsDansSD.get(listeJLabelClientsDansSD.size()-1).setText(client.getPseudo());
//        	listeJLabelClient.get(listeJLabelClient.size()-1).setIcon(new javax.swing.ImageIcon(client.getAvatar()));
        	listeJLabelClientsDansSD.get(listeJLabelClientsDansSD.size()-1).setToolTipText(client.getPseudo());
        	if (!client.isStatusDeConnection()) {
        		listeJLabelClientsDansSD.get(listeJLabelClientsDansSD.size()-1).setEnabled(false);
        	}	
        	jPanel1.add(listeJLabelClientsDansSD.get(listeJLabelClientsDansSD.size()-1));
        }

        jPanelDesabonnerSD.setBackground(new java.awt.Color(-855608,true));

        jButtonDesabonnerSD.setText("Desabonner");
        jButtonDesabonnerSD.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e){
				controlleur.desabonnerSD(modele.getSalle());
            }
        });

        javax.swing.GroupLayout jPanelDesabonnerSDLayout = new javax.swing.GroupLayout(jPanelDesabonnerSD);
        jPanelDesabonnerSD.setLayout(jPanelDesabonnerSDLayout);
        jPanelDesabonnerSDLayout.setHorizontalGroup(
            jPanelDesabonnerSDLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelDesabonnerSDLayout.createSequentialGroup()
                .addComponent(jButtonDesabonnerSD, javax.swing.GroupLayout.PREFERRED_SIZE, 122, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanelDesabonnerSDLayout.setVerticalGroup(
            jPanelDesabonnerSDLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelDesabonnerSDLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jButtonDesabonnerSD))
        );

        jPanelQuitterSD.setBackground(new java.awt.Color(-855608,true));

        jButtonQuitterSD.setText("Quitter");
        jButtonQuitterSD.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e){
				controlleur.quitterSD(modele.getSalle());
            }
        });

        javax.swing.GroupLayout jPanelQuitterSDLayout = new javax.swing.GroupLayout(jPanelQuitterSD);
        jPanelQuitterSD.setLayout(jPanelQuitterSDLayout);
        jPanelQuitterSDLayout.setHorizontalGroup(
            jPanelQuitterSDLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jButtonQuitterSD, javax.swing.GroupLayout.DEFAULT_SIZE, 116, Short.MAX_VALUE)
        );
        jPanelQuitterSDLayout.setVerticalGroup(
            jPanelQuitterSDLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelQuitterSDLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jButtonQuitterSD))
        );
        
        jButtonAime.setText("J'aime?");
        jButtonAime.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e){
				controlleur.apprecierUnMessage();
            }
        });

        javax.swing.GroupLayout jPanelContenuSalleDiscussionLayout = new javax.swing.GroupLayout(jPanelContenuSalleDiscussion);
        jPanelContenuSalleDiscussion.setLayout(jPanelContenuSalleDiscussionLayout);
        jPanelContenuSalleDiscussionLayout.setHorizontalGroup(
            jPanelContenuSalleDiscussionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelContenuSalleDiscussionLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelContenuSalleDiscussionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPaneListeMessages, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 813, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelContenuSalleDiscussionLayout.createSequentialGroup()
                        .addGroup(jPanelContenuSalleDiscussionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabelTitreSalleDiscussion)
                            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 651, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 28, Short.MAX_VALUE)
                        .addGroup(jPanelContenuSalleDiscussionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jPanelQuitterSD, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jPanelDesabonnerSD, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelContenuSalleDiscussionLayout.createSequentialGroup()
                        .addComponent(jButtonAime)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 663, Short.MAX_VALUE)
                        .addComponent(jButtonSoumettreMessage))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 813, Short.MAX_VALUE))
                .addContainerGap())
        );
/*        javax.swing.GroupLayout jPanelContenuSalleDiscussionLayout = new javax.swing.GroupLayout(jPanelContenuSalleDiscussion);
        jPanelContenuSalleDiscussion.setLayout(jPanelContenuSalleDiscussionLayout);
        jPanelContenuSalleDiscussionLayout.setHorizontalGroup(
            jPanelContenuSalleDiscussionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelContenuSalleDiscussionLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelContenuSalleDiscussionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPaneListeMessages, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 813, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelContenuSalleDiscussionLayout.createSequentialGroup()
                        .addGroup(jPanelContenuSalleDiscussionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabelTitreSalleDiscussion)
                            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 651, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 28, Short.MAX_VALUE)
                        .addGroup(jPanelContenuSalleDiscussionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jPanelQuitterSD, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jPanelDesabonnerSD, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelContenuSalleDiscussionLayout.createSequentialGroup()
                        	.addComponent(jButtonAime)
                        	.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 663, Short.MAX_VALUE)
                        	.addComponent(jButtonSoumettreMessage))
                            //.addComponent(jButtonSoumettreMessage, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 813, Short.MAX_VALUE))
                .addContainerGap())
        ); */
        jPanelContenuSalleDiscussionLayout.setVerticalGroup(
            jPanelContenuSalleDiscussionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelContenuSalleDiscussionLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelContenuSalleDiscussionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelContenuSalleDiscussionLayout.createSequentialGroup()
                        .addComponent(jLabelTitreSalleDiscussion)
                        .addGap(18, 18, 18)
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanelContenuSalleDiscussionLayout.createSequentialGroup()
                        .addComponent(jPanelDesabonnerSD, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jPanelQuitterSD, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(18, 18, 18)
                .addComponent(jScrollPaneListeMessages, javax.swing.GroupLayout.DEFAULT_SIZE, 346, Short.MAX_VALUE)
                .addGap(18, 18, 18)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(12, 12, 12)
                .addGroup(jPanelContenuSalleDiscussionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButtonSoumettreMessage)
                    .addComponent(jButtonAime))
//                .addComponent(jButtonSoumettreMessage)
                .addContainerGap())
        );

        jPanelConsulterProfil2.setBackground(new java.awt.Color(-855608,true));
        jPanelConsulterProfil2.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(-855788,true), 5, true));

        jButtonAjouterSalleDiscussion.setFont(new java.awt.Font("Dialog", 0, 18));
        jButtonAjouterSalleDiscussion.setText("<HTML><CENTER>Ajouter une salle<BR>de discussion</HTML>");
        jButtonAjouterSalleDiscussion.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                controlleur.afficherAjouterSalleDiscussion();
            }
        });

        javax.swing.GroupLayout jPanelConsulterProfil2Layout = new javax.swing.GroupLayout(jPanelConsulterProfil2);
        jPanelConsulterProfil2.setLayout(jPanelConsulterProfil2Layout);
        jPanelConsulterProfil2Layout.setHorizontalGroup(
            jPanelConsulterProfil2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelConsulterProfil2Layout.createSequentialGroup()
                .addContainerGap(40, Short.MAX_VALUE)
                .addComponent(jButtonAjouterSalleDiscussion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(60, 60, 60))
        );
        jPanelConsulterProfil2Layout.setVerticalGroup(
            jPanelConsulterProfil2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelConsulterProfil2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jButtonAjouterSalleDiscussion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanelConsulterProfil.setBackground(new java.awt.Color(-855608,true));
        jPanelConsulterProfil.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(-855788,true), 5, true));

        jButtonModifierProfil.setFont(new java.awt.Font("Dialog", 0, 18)); // NOI18N
        jButtonModifierProfil.setText("<HTML><CENTER>Modifier mon<BR>profil</HTML>");
        jButtonModifierProfil.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                controlleur.modifierProfil();
            }
        });

        javax.swing.GroupLayout jPanelConsulterProfilLayout = new javax.swing.GroupLayout(jPanelConsulterProfil);
        jPanelConsulterProfil.setLayout(jPanelConsulterProfilLayout);
        jPanelConsulterProfilLayout.setHorizontalGroup(
            jPanelConsulterProfilLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelConsulterProfilLayout.createSequentialGroup()
                .addGap(62, 62, 62)
                .addComponent(jButtonModifierProfil, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(69, Short.MAX_VALUE))
        );
        jPanelConsulterProfilLayout.setVerticalGroup(
            jPanelConsulterProfilLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelConsulterProfilLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jButtonModifierProfil, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(frame.getContentPane());
        frame.getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanelBanierePrincipale, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jPanelContenuSalleDiscussion, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jPanelOtherClientsAvatar, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 847, Short.MAX_VALUE))
                        .addGap(18, 18, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(jPanelQuitter, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jPanelConsulterProfil2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(jPanelConsulterProfil, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jPanelSallesDiscussionsDispo, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanelBanierePrincipale, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jPanelOtherClientsAvatar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanelConsulterProfil, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanelSallesDiscussionsDispo, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGap(18, 18, 18)
                        .addComponent(jPanelConsulterProfil2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jPanelQuitter, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jPanelContenuSalleDiscussion, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );

        frame.pack();
    }
    
	public javax.swing.JFrame getFrame() {
		return frame;
	}

	public void setFrame(javax.swing.JFrame frame) {
		this.frame = frame;
	}
	
	public void updateMessages() {
		jTextAreaTousLesMessages.setEditable(false);
		jTextAreaTousLesMessages.setContentType("text/html");
        StringBuilder texte = new StringBuilder();
        texte.append("<HTML>");
        for (Message mes : modele.getSalle().getListeMessages()) {
        	texte.append("(id = " + Integer.toString(mes.getIdMsg()) + ")");
        	texte.append("<FONT COLOR=\"blue\"> (");
        	texte.append(mes.getPseudoAuteur());
        	texte.append("): </FONT>");
        	texte.append(mes.getContenue());
        	texte.append("&nbsp;&nbsp;&nbsp;&nbsp(<FONT COLOR=\"green\"> +");
        	texte.append(mes.getLike());
        	texte.append("</FONT>, <FONT COLOR=\"red\"> -");
        	texte.append(mes.getDislike());
        	texte.append("</FONT> )<BR>");
        }
        texte.append("</HTML>");
        jTextAreaTousLesMessages.setText(texte.toString());
        jScrollPaneListeMessages.setViewportView(jTextAreaTousLesMessages);
        jTextAreaTousLesMessages.updateUI();
	}
}
